﻿package mortal.game.view.mainUI.rightTop
{
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.window.resWin.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class NetWorkStatePanel extends ResBasePanel
    {
        private const _interval:int = 10;
        private var _frame:SecTimer;
        private var bestNetWork:GBitmap;
        private var normalNetWork:GBitmap;
        private var badNetWork:GBitmap;
        private var netWorkText:GTextFiled;

        public function NetWorkStatePanel()
        {
            super(ResFileConst.netWork);
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            this.bestNetWork = UIFactory.gBitmap(ImagesConst.bestNetWork, 35, 5, this);
            this.normalNetWork = UIFactory.gBitmap(ImagesConst.normalNetWork, 35, 7, this);
            this.badNetWork = UIFactory.gBitmap(ImagesConst.badNetWork, 35, 9, this);
            this.netWorkText = UIFactory.gTextField(Language.getString(35372), 0, 0, 60, 18, this);
            var _loc_1:Boolean = false;
            this.badNetWork.visible = false;
            var _loc_1:* = _loc_1;
            this.normalNetWork.visible = _loc_1;
            this.bestNetWork.visible = _loc_1;
            this._frame = new SecTimer(this._interval);
            this._frame.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            this._frame.start();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.bestNetWork.dispose(param1);
            this.normalNetWork.dispose(param1);
            this.badNetWork.dispose(param1);
            this.netWorkText.dispose(param1);
            this.bestNetWork = null;
            this.normalNetWork = null;
            this.badNetWork = null;
            this.netWorkText = null;
            return;
        }// end function

        private function onEnterFrameHandler(param1:SecTimer) : void
        {
            if (Cache.instance.rightTop.networkPingArray.length > 0)
            {
                Cache.instance.rightTop.networkPingArray.length = 0;
                Cache.instance.rightTop.Delay = int.MAX_VALUE;
                this.refresh();
            }
            else
            {
                Cache.instance.rightTop.networkPingArray.push(getTimer());
                Dispatcher.dispatchEvent(new DataEvent(EventName.NetWorkPing, getTimer().toString()));
            }
            return;
        }// end function

        override public function refresh(param1:Boolean = false) : void
        {
            super.refresh(param1);
            if (!allowRefresh)
            {
                return;
            }
            var _loc_2:Boolean = false;
            this.badNetWork.visible = false;
            var _loc_2:* = _loc_2;
            this.normalNetWork.visible = _loc_2;
            this.bestNetWork.visible = _loc_2;
            switch(Cache.instance.rightTop.State)
            {
                case 1:
                {
                    this.bestNetWork.visible = true;
                    toolTipData = Language.getStringByParam(35373, GlobalStyle.colorLv, Cache.instance.rightTop.Delay);
                    break;
                }
                case 2:
                {
                    this.normalNetWork.visible = true;
                    toolTipData = Language.getStringByParam(35374, GlobalStyle.colorHuang, Cache.instance.rightTop.Delay);
                    break;
                }
                case 3:
                {
                    this.badNetWork.visible = true;
                    toolTipData = Language.getStringByParam(35375, GlobalStyle.colorHong, Cache.instance.rightTop.Delay);
                    break;
                }
                case 4:
                {
                    toolTipData = Language.getStringByParam(35376, GlobalStyle.colorHong);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
